// const { waitForDebugger } = require("inspector");

$(function () {
    layui.use('carousel', function () {
        var carousel = layui.carousel;
        function loadSwiperList() {
            $.ajax({
                type: 'get',
                url: 'http://localhost:8888/api/swipers',
                success: function (res) {
                    if (res.status === 0) {
                        let arr = []
                        res.data.forEach(function (item) {
                            arr.push(`
                            <li class="img-effect">
                            <a href="javascript:;">
                              <img src="${'http://localhost:8888/uploads/' + item.swiperimg}" alt="">
                            </a >
                          </li >
                            `)
                        })
                        // 接入轮播图的盒子里
                        $('#kr_carousel ul').html(arr.join(''))
                        // 轮播交互
                        carousel.render({
                            elem: '#kr_carousel',
                            width: 720,
                            height: 300,
                            interval: 3000
                        });
                    }
                }
            })
        }
        loadSwiperList()
        //---------------- 加载友情链接-----------------------------
        function linkList() {
            $.ajax({
                type: 'get',
                url: 'http://localhost:8888/api/links',
                success: function (res) {
                    // 判断请求是否成功
                    if (res.status === 0) {
                        // 那么请求成功
                        let arr = []
                        res.data.forEach(function (item) {
                            arr.push(`<dd>
                            <a href="javascript:;">
                              <img src="${'http://localhost:8888/uploads/' + item.linkicon}" alt="">
                            </a>
                          </dd>`)
                        })
                        $('.kr_collaborator').html(arr.join(''))
                    }
                }
            })
        }
        linkList()

    })

})
